package com.wnxy.sdd.redis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;

import java.util.Set;

@SpringBootTest
public class RedisTestSet {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Test
    public void test(){
        // 操作set集合
        SetOperations<String, Object> setOperations = redisTemplate.opsForSet();

        setOperations.add("all_image","1.jpb","a.jpg","b.jpg");
        setOperations.add("db_image","b.jpg");
        // 差集
        Set<Object> difference = setOperations.difference("all_image", "db_image");
        System.out.println("差集 = " + difference);
        // 交集
        Set<Object> intersect = setOperations.intersect("all_image", "db_image");
        System.out.println("交集 = " + intersect);
        // 并集
        Set<Object> union = setOperations.union("all_image", "all_image");
        System.out.println("并集 = " + union);
    }
}
